import count from '@dfeidao/atom-nodejs/db/count';
import query from '@dfeidao/atom-nodejs/db/query';
import format from '@dfeidao/atom-nodejs/dt/format';
import { systemid } from '../../atom/config';


interface Message {
	filter: {
		resume_name?: string;
		op_cont?: string;
		operation_time: string;
		client_no: string;

	};
	page_size: number;
	page_no: number;
	asc?: string[];
	desc?: string[];

}
interface Isystem {
	operation_time: number;
	operation_times: string;
}
export default async function atom(msg: Message, action_id: string, session_id: string) {
	const { exec, prepare } = query(action_id, session_id, systemid);
	prepare('system_log', ['_id', 'operation_time', 'pub_user_no', 'operate_type', 'resume_name', 'productid', 'op_cont'], msg.filter, msg.page_size, msg.page_no, msg.asc, msg.desc);

	const [data] = await exec<Isystem>();

	data.forEach((v) => {
		v.operation_times =
			format(v.operation_time, 'YYYY-MM-DD HH:mm');
	});
	const ct = count(action_id, session_id, systemid);
	ct.prepare('system_log', msg.filter);
	const [res1] = await ct.exec();

	return { dataArry: data, count: res1, page_no: msg.page_no, page_size: msg.page_size };
}
